package com.controller;

import com.service.UserService;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "Servlet2", value = "/selectAll2")
public class Servlet2 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //调用spring提供的工具类 获取创建的spring容器
        WebApplicationContext applicationContext = WebApplicationContextUtils.findWebApplicationContext(request.getServletContext());
        UserService bean = applicationContext.getBean(UserService.class);
        System.out.println("11111");
        bean.findAll();
    }
}
